#include "StdAfx.h"
#include "CmutaAlgoDemo.h"
#include <algorithm>
#include <iostream>
#include <vector>
#include "RegsistFile.h"

CmutaAlgoDemo::CmutaAlgoDemo(void)
{
	RegistCommond();
}

CmutaAlgoDemo::~CmutaAlgoDemo(void)
{
}

void CmutaAlgoDemo::RegistCommond()
{
	/// regist
	RegsistFace::RegsistPro(m_mapCommond);
}

pair<CString,ICommand*> CmutaAlgoDemo::Comp(ICommand* pFace)
{
	return make_pair(pFace->GetCommondName(),pFace);
}

bool CmutaAlgoDemo::ShowCommondResult( const CString& strCommondName )
{
	map<CString,ICommand*>::iterator it = m_mapCommond.find(strCommondName);
	if(it != m_mapCommond.end())
	{
		it->second->Run();
		return true;
	}
	return false;
}

void CmutaAlgoDemo::Release()
{
	for_each(m_mapCommond.begin(),m_mapCommond.end(),ReleaseEx<pair<CString,ICommand*>>());
}

//////////////////////////////////////////////////////////////////////////
CSortCommand::CSortCommand()
{

}

CSortCommand::~CSortCommand()
{

}

void CSortCommand::Run()
{
	/// common int array
	const int nCount = 8;
	int nDataArray[nCount] = {2,3,1,4,6,3,7,9};
	sort(nDataArray,nDataArray+nCount);
	copy(nDataArray,nDataArray+nCount,ostream_iterator<int>(cout," "));

	cout << endl;

	/// common int vector
	vector<int> nDataVec;
	for (int nIndex = nCount; nIndex > 0; --nIndex)
	{
		nDataVec.push_back(nIndex);
	}
	sort(nDataVec.begin(),nDataVec.end());
	copy(nDataVec.begin(),nDataVec.end(),ostream_iterator<int>(cout," "));

	cout << endl;
}


//////////////////////////////////////////////////////////////////////////
CStable_sortCommand::CStable_sortCommand()
{

}

CStable_sortCommand::~CStable_sortCommand()
{

}

void CStable_sortCommand::Run()
{
	/// common int array
	const int nCount = 8;
	int nDataArray[nCount] = {2,3,1,4,6,3,7,9};
	stable_sort(nDataArray,nDataArray+nCount);
	copy(nDataArray,nDataArray+nCount,ostream_iterator<int>(cout," "));

	cout << endl;

	/// common int vector
	vector<int> nDataVec;
	for (int nIndex = nCount; nIndex > 0; --nIndex)
	{
		nDataVec.push_back(nIndex);
	}
	stable_sort(nDataVec.begin(),nDataVec.end());
	copy(nDataVec.begin(),nDataVec.end(),ostream_iterator<int>(cout," "));

	cout << endl;
}

//////////////////////////////////////////////////////////////////////////
CPartial_sortCommand::CPartial_sortCommand()
{

}

CPartial_sortCommand::~CPartial_sortCommand()
{

}

void CPartial_sortCommand::Run()
{

}
